// import Vue from 'vue'
// import Vuex from 'vuex'
// Vue.use(Vuex)
// const store = () => new Vuex.Store({
//   state: {
//     counter: 0,userlist:[]
//   },
//   mutations: {
//     increment (state) {
//       state.counter+=1;
//     },setuserlist(state,data){
//         state.userlist=data;
//     }
//   }
// })
// export default store

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
// window.fetch() 的 Polyfill
//require('whatwg-fetch')
import axios from "../tools/axios"
export const state=()=>{
    return {
        counter:0,userlist:[],user:{}
    }
}
export const mutations={
    increment (state) {
        state.counter+=1;
    },setuserlist(state,data){
        state.userlist=data;
    },setuser(state,data){
        state.user=data;
    }
}
export const actions={
    async nuxtServerInit({ commit }, {req}) {
        //console.log('init',req.headers.cookie);
        var t=await axios.get('/login/user',{headers:req.headers});
        commit('setuser', t.data || {})
    }
}